home *** CD-ROM | disk | FTP | other *** search
- //
- // $Id$
- //
- // Program : BigIcon.cpp
- //
- // Author : James Bish
- //
- // Date : 06/02/93
- //
- // Purpose : To create a BigIcon custom control (vbx) for Visual
- // Basic.
- // $Log$
- //
- // Copyright (c) Bish Programming 1993 - All Rights Reserved.
- //
-
- #include "stdafx.h"
-
- //
- // Methods for the Popup Window.
- //
-
- myPopupWnd::myPopupWnd(CVBCtlWnd *pCtl, USHORT iProperty)
- : CVBPopupWnd(pCtl, iProperty)
- {
- }
-
- //
- // Create the control window.
- //
- IMPLEMENT_DYNCREATE(myCtlWnd, CVBCtlWnd)
-
- myCtlWnd::myCtlWnd()
- {
- }
-
- myCtlWnd::myCtlWnd(HWND hwnd)
- {
- CVBCtlWnd::CVBCtlWnd(hwnd);
- }
-
-
- //
- // The CVBDLL derived application object.
- //
- myVBDLL theApp;
-
- //
- // myVBDLL::InitInstance()
- //
- // Perform one time initialization here, eg. (register the visual basic
- // control models.
- //
- BOOL myVBDLL::InitInstance()
- {
- SetPopupWnd(FALSE);
-
- //
- // Add the VB Control Model.
- //
-
- AddModel("BigIcon", 0,CS_VREDRAW | CS_HREDRAW, 0, sizeof(BigIcon),
- IDBMP_BIGICON, NULL, IPROP_BIGICON_CTLNAME,
- IEVENT_BIGICON_CLICK, -1, RUNTIME_CLASS(myCtlWnd));
-
- //
- // Add the standard properties.
- //
-
- AddProperty("BigIcon", PPROPINFO_STD_CTLNAME );
- AddProperty("BigIcon", PPROPINFO_STD_INDEX );
- AddProperty("BigIcon", PPROPINFO_STD_LEFT );
- AddProperty("BigIcon", PPROPINFO_STD_TOP );
- AddProperty("BigIcon", PPROPINFO_STD_WIDTH );
- AddProperty("BigIcon", PPROPINFO_STD_HEIGHT );
- AddProperty("BigIcon", PPROPINFO_STD_VISIBLE );
- AddProperty("BigIcon", PPROPINFO_STD_PARENT );
- AddProperty("BigIcon", PPROPINFO_STD_DRAGMODE );
- AddProperty("BigIcon", PPROPINFO_STD_DRAGICON );
- AddProperty("BigIcon", PPROPINFO_STD_TAG );
- AddProperty("BigIcon", PPROPINFO_STD_HWND );
- AddProperty("BigIcon", PPROPINFO_STD_BACKCOLOR );
-
- //
- // Add custom properties.
- //
-
- AddProperty("BigIcon", "Picture",
- DT_PICTURE | PF_fGetData | PF_fSetCheck | PF_fSetData |
- PF_fSaveData | PF_fSetMsg, OFFSETIN(BigIcon,hpicPict));
-
- AddProperty("BigIcon", "ShadowWidth",
- DT_SHORT | PF_fGetData | PF_fSetMsg | PF_fSetData | PF_fSaveData,
- OFFSETIN(BigIcon, ShadowWidth));
-
- AddProperty("BigIcon", "ShadowColor",
- DT_COLOR | PF_fGetData | PF_fSetMsg | PF_fSetData | PF_fSaveData,
- OFFSETIN(BigIcon, ShadowColor));
-
- AddProperty("BigIcon", "(About)",
- DT_BOOL | PF_fGetData | PF_fSetMsg | PF_fSaveData | PF_fGetHszMsg,
- OFFSETIN(BigIcon, About));
-
- //
- // Add standard events.
- //
-
- AddEvent("BigIcon", PEVENTINFO_STD_CLICK );
- AddEvent("BigIcon", PEVENTINFO_STD_DRAGDROP );
- AddEvent("BigIcon", PEVENTINFO_STD_DRAGOVER );
-
- return TRUE;
- }
-
- //
- // Message map for myCtlWnd
- //
- BEGIN_MESSAGE_MAP(myCtlWnd, CVBCtlWnd)
- ON_WM_PAINT()
- ON_WM_CREATE()
- ON_WM_NCDESTROY()
-
- ON_MESSAGE(VBM_SETPROPERTY,OnVBSetProperty)
- ON_MESSAGE(VBM_CHECKPROPERTY, OnVBCheckProperty)
- ON_MESSAGE(VBM_GETPROPERTYHSZ, OnVBGetPropertyHsz)
- ON_MESSAGE(VBM_INITPROPPOPUP, OnVBInitPropPopup)
- END_MESSAGE_MAP()
-
- //
- // myCtlWnd::OnPaint()
- //
- // Handle painting of the control.
- //
- void myCtlWnd::OnPaint()
- {
- CPaintDC *pDC = new CPaintDC(this); // device context for painting
- HPIC hpic;
- PIC pic;
- CRect rect;
- GetClientRect(rect);
-
- int cxClient = rect.Width();
- int cyClient = rect.Height();
- COLORREF ShadowColor = (COLORREF)LpBigIconDEREF(m_hCtl)->ShadowColor;
- int ShadowWidth = (int)LpBigIconDEREF(m_hCtl)->ShadowWidth;
-
- //
- // Fill the window with the color of the parent window.
- //
-
- CBrush *cBr;
-
- cBr = CBrush::FromHandle( (HBRUSH)
- GetParent()->SendMessage(WM_CTLCOLOR,(WPARAM)pDC->m_hDC,
- MAKELONG(m_hWnd,0)));
- pDC->FillRect(rect, cBr);
-
- //
- // Draw the border around the window.
- //
-
- CPen pen;
- pen.CreateStockObject(BLACK_PEN);
- CPen* pPenOld = pDC->SelectObject(&pen);
- pDC->Rectangle(0, 0, cxClient-ShadowWidth, cyClient-ShadowWidth);
- if (pPenOld) {
- pDC->SelectObject(pPenOld);
- pen.DeleteObject();
- }
-
- //
- // draw shadows around icon
- //
- CBrush br;
- br.CreateSolidBrush(ShadowColor);
- rect.SetRect(cxClient-ShadowWidth, ShadowWidth, cxClient, cyClient);
- pDC->FillRect(rect, &br);
- rect.SetRect(ShadowWidth, cyClient-ShadowWidth, cxClient, cyClient);
- pDC->FillRect(rect, &br);
-
- //
- // Get the picture.
- //
-
- hpic = LpBigIconDEREF(m_hCtl)->hpicPict;
-
- //
- // Set the palette.
- //
-
- if( VBGetVersion() >= VB200_VERSION )
- VBGetPicEx(hpic, &pic, VB_VERSION );
- else {
- pic.picData.bmp.hpal = NULL;
- VBGetPic(hpic, &pic );
- }
-
- //
- // Draw the picture.
- //
-
- switch( pic.picType ) {
- case PICTYPE_BITMAP: {
- BITMAP bitmap;
- GetObject(pic.picData.bmp.hbitmap, sizeof(BITMAP),
- (LPSTR)&bitmap);
-
- CDC dcMem;
- if( !dcMem.CreateCompatibleDC(pDC))
- break;
-
- dcMem.SelectObject(pic.picData.bmp.hbitmap);
-
- pDC->StretchBlt(2, 2, cxClient-ShadowWidth-ShadowWidth,
- cyClient-ShadowWidth-ShadowWidth,
- &dcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
- }
- break;
-
- case PICTYPE_ICON: {
- // draw icon into off-screen bitmap
- int cxIcon = ::GetSystemMetrics(SM_CXICON);
- int cyIcon = ::GetSystemMetrics(SM_CYICON);
-
- CBitmap bitmap;
- if( !bitmap.CreateCompatibleBitmap(pDC,cxIcon,cyIcon))
- break;
-
- CDC dcMem;
- if( !dcMem.CreateCompatibleDC(pDC))
- break;
-
- dcMem.SelectObject(&bitmap);
-
- dcMem.StretchBlt(0,0, cxIcon, cyIcon, pDC,
- 2, 2, cxClient-ShadowWidth-ShadowWidth,
- cyClient-ShadowWidth-ShadowWidth,
- SRCCOPY);
-
- dcMem.DrawIcon(0,0,pic.picData.icon.hicon);
-
- pDC->StretchBlt(2, 2, cxClient-ShadowWidth-ShadowWidth,
- cyClient-ShadowWidth-ShadowWidth,
- &dcMem, 0, 0, cxIcon, cyIcon, SRCCOPY);
- }
- break;
-
- case PICTYPE_METAFILE: {
- pDC->SetMapMode(MM_ANISOTROPIC);
- pDC->SetWindowExt(1000,1000);
- pDC->SetWindowOrg(-2,-2);
- pDC->SetViewportExt(cxClient-ShadowWidth,cyClient-ShadowWidth);
- pDC->PlayMetaFile((HMETAFILE) pic.picData.wmf.hmeta);
- }
- break;
-
- case PICTYPE_NONE:
- break;
- }
-
- delete pDC;
- }
-
- //
- // myCtlWnd::OnVBSetProperty
- //
- // Handle changes in the user properties of the control
- //
- LRESULT myCtlWnd::OnVBSetProperty(WPARAM wp, LPARAM lp)
- {
- switch( wp ) {
- case IPROP_BIGICON_BKCOLOR:
- InvalidateRect(NULL, TRUE );
- return( 0L );
-
- case IPROP_BIGICON_SHADOWCOLOR:
- LpBigIconDEREF(m_hCtl)->ShadowColor = (COLORREF)lp;
- InvalidateRect( NULL, TRUE );
- return( 0L );
-
- case IPROP_BIGICON_SHADOWWIDTH:
- LpBigIconDEREF(m_hCtl)->ShadowWidth = (SHORT) lp;
- InvalidateRect( NULL, TRUE );
- return( 0L );
- }
-
- //
- // Return the parent function.
- //
-
- return CVBCtlWnd::OnVBSetProperty(wp, lp);
- }
-
- //
- // myCtlWnd::OnVBCheckProperty
- //
- // Force a repaint of the control if any of the property values
- // changes
- //
- LRESULT myCtlWnd::OnVBCheckProperty(WPARAM wp, LPARAM lp )
- {
- switch( wp ) {
- case IPROP_BIGICON_PICT:
- InvalidateRect( NULL, TRUE);
- return( 0L );
- }
-
- //
- // Call the parent method.
- //
-
- return CVBCtlWnd::OnVBCheckProperty(wp, lp);
- }
-
- //
- // myCtlWnd::OnVBGetPropertyHsz
- //
- // Force the string for the About Box message.
- //
- LRESULT myCtlWnd::OnVBGetPropertyHsz(WPARAM wp, LPARAM lp)
- {
- switch( wp ) {
- case IPROP_BIGICON_ABOUT:
- HSZ the_hsz;
-
- the_hsz = ::VBCreateHsz((HANDLE) _FP_SEG(m_hCtl),
- "Click on \"...\" for About Box");
- _fmemcpy( (LPSTR *)lp, (LPSTR *) &the_hsz, sizeof(HSZ));
- return( 0L );
- break;
- }
-
- //
- // Call the parent method.
- //
-
- return CVBCtlWnd::OnVBGetPropertyHsz(wp, lp);
- }
-
- //
- // myCtlWnd::OnVBInitPropPopup
- //
- // Create a window and pass a handle back to visual basic. This
- // must be done to display dialog boxes in Visual Basic.
- //
- LRESULT myCtlWnd::OnVBInitPropPopup(WPARAM wp, LPARAM lp )
- {
- switch( wp ) {
- case IPROP_BIGICON_ABOUT: {
- myPopupWnd *x = new myPopupWnd(this, IPROP_BIGICON_ABOUT);
-
- if( x )
- return( MAKELONG(x->m_hWnd,0) );
- else
- return NULL;
- }
- break;
-
- case IPROP_BIGICON_SHADOWCOLOR: {
- myPopupWnd *x = new myPopupWnd(this, IPROP_BIGICON_SHADOWCOLOR);
-
- if( x )
- return( MAKELONG( x->m_hWnd, 0) );
- else
- return NULL;
- }
- break;
- }
-
- //
- // Call the parent method.
- //
-
- return CVBCtlWnd::OnVBInitPropPopup(wp, lp);
- }
-
- //
- // myCtlWnd::OnCreate
- //
- // Set the default values for user defined properties.
- //
- int myCtlWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CVBCtlWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- VBSetControlProperty(m_hCtl, IPROP_BIGICON_BKCOLOR,
- ::GetSysColor(COLOR_WINDOW));
-
- VBSetControlProperty(m_hCtl, IPROP_BIGICON_SHADOWWIDTH, 4 );
- VBSetControlProperty(m_hCtl, IPROP_BIGICON_SHADOWCOLOR,
- RGB(0,0,0));
-
- return 0;
- }
-
- //
- // myCtlWnd::OnNcDestroy
- //
- // Free memory used by picture objects.
- //
- void myCtlWnd::OnNcDestroy()
- {
- CVBCtlWnd::OnNcDestroy();
-
- //
- // Release the picture.
- //
-
- LPBIGICON pict;
-
- pict = (LPBIGICON)LpBigIconDEREF(m_hCtl);
- VBFreePic(pict->hpicPict);
- }
-
- //
- // myPopupWnd::DoPopupDlg
- //
- // Virtual function that must be overloaded with your implementation.
- //
- void myPopupWnd::DoPopupDlg()
- {
- ASSERT_VALID(this);
-
- switch( m_iProperty ) {
- case IPROP_BIGICON_ABOUT: {
- CVBDialog *AboutDlg = new CVBDialog(IDD_ABOUTDLG, this);
- AboutDlg->DoModal();
- delete AboutDlg;
- }
- break;
-
- case IPROP_BIGICON_SHADOWCOLOR: {
- CVBColorDialog *ShadowColorDlg = new CVBColorDialog(0,0, this );
- if( ShadowColorDlg->DoModal() == IDOK)
- SetControlProperty((LONG) ShadowColorDlg->GetColor());
- delete ShadowColorDlg;
- }
- break;
- }
- }
-
-